<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>案件管理-双打报表（全市）</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style>
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <!--案件列表-->
                <div id="ajForm" class="layui-card-body">
                    <form id="searchForm" class="layui-form" method="post" style="margin-left: 10px">
                        <div class="layui-form-item">
                            <div class="layui-row">
                                <div class="layui-col-xs3">
                                    <label for="jcajbh"></label>
                                    <input type="text" id="jcajbh" class="layui-input" autocomplete="off"
                                           placeholder="请输案件编号">
                                </div>
                                <div class="layui-col-xs3">
                                    <label for="nsrsbh"></label>
                                    <input type="text" id="nsrsbh" class="layui-input" autocomplete="off"
                                           placeholder="请输纳税人识别号">
                                </div>
                                <div class="layui-col-xs3">
                                    <label for="nsrmc"></label>
                                    <input type="text" id="nsrmc" class="layui-input" autocomplete="off"
                                           placeholder="请输入纳税人名称">
                                </div>
                                <div class="layui-col-xs3">
                                    <label for="ayxfsj"></label>
                                    <input type="text" class="layui-input" id="ayxfsj"
                                           placeholder="请输入案源下发时间">
                                </div>
                            </div>
                            <div class="layui-row" style="margin-top: 20px;display: flex; justify-content: center;">
                                <button type="button" class="layui-btn" lay-submit="" lay-filter="search">查询</button>
                                <button type="button" class="layui-btn" lay-submit="" lay-filter="reset">重置</button>
                                <button type="button" class="layui-btn" lay-submit="" lay-filter="export">导出</button>

                            </div>
                        </div>
                        <table class="layui-hide" id="ajwh_table" lay-filter="ajwh_table"></table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    //获取token
    var token = CoreUtil.getData("access_token");
    //地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var tableIns1;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var startTime = null;
    var endTime = null;
    //要求结案时间
    var yqjasjTime = null;
    layui.use(['table', 'laypage', 'layer', 'laydate'], function () {
        // 案源字典下拉选
        CoreUtil.sendPost("/attention/attentionMgr/queryAylxzdList", null, function (res) {
            if (res.code === 0) {
                let value = res.data; // 接口返回的数据
                let opt = "<option value=''>请选择科室</option>"; // 默认选项
                // 遍历接口返回的数据，生成选项
                for (let i in value) {
                    opt += '<option value="' + value[i].zdmc + '">' + value[i].zdmc + '</option>';
                }
                // 将生成的选项插入到 select 元素中
                $("#aylxSelect").html(opt);
                // 渲染 layui 的 select 组件
                form.render('select'); // 注意：必须调用渲染方法以更新 select 组件
            } else {
                // 如果接口返回错误
                layer.msg(res.msg, {icon: 2}); // 提示错误信息
                return false;
            }
        });
        // 案件列表
        tableIns1 = table.render({
            elem: '#ajwh_table'
            , page: true //开启分页
            , contentType: 'application/json'
            , headers: {"authorization": token}
            , where: {
                "cxbz": "qs"
            }
            , url: '/attention/attentionMgr/queryAjwhTable' //数据接口
            , method: 'POST'
            , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                }
            }
            , cols: [
                [
                    {field: 'jcajxxuuid', title: '稽查案件信息uuid', width: 100, hide: true},
                    {field: 'jcajbh', title: '案件编号', width: 200, align: "center", sort: true},
                    {field: 'nsrsbh', title: '纳税人识别号', width: 200, align: "center", sort: true},
                    {field: 'nsrmc', title: '企业名称', width: 200, align: "center", sort: true},
                    {field: 'aylx', title: '案源类型', width: 200, align: "center", sort: true},
                    {field: 'bz', title: '备注', width: 200, align: "center", sort: true},
                    {
                        field: 'ayxfsj',
                        title: '案源下发时间',
                        width: 160,
                        align: "center",
                        sort: true,
                        templet: function (d) {
                            if (!d.ayxfsj) {
                                return '';
                            }
                            return layui.util.toDateString(d.ayxfsj, 'yyyy-MM-dd');
                        }
                    },
                    {
                        field: 'yqjasj',
                        title: '要求结案时间',
                        width: 160,
                        align: "center",
                        sort: true,
                        templet: function (d) {
                            if (!d.yqjasj) {
                                return '';
                            }
                            return layui.util.toDateString(d.yqjasj, 'yyyy-MM-dd');
                        }
                    },
                    {field: 'ajjczt', title: '案件检查状态', width: 140, align: "center", sort: true},
                    {field: 'jcfs', title: '检查方式', width: 100, align: "center", sort: true},
                    {field: 'zxqk', title: '注销情况', width: 100, align: "center", sort: true},
                    {field: 'ztqk', title: '走逃情况', width: 100, align: "center", sort: true},
                    {field: 'sfxk', title: '是否虚开', width: 100, align: "center", sort: true},
                    {field: 'lhzb', title: '联合侦办', width: 100, align: "center", sort: true},
                    {field: 'ysgaqk', title: '移送公安情况', width: 150, align: "center", sort: true},
                    {field: 'zpdwfpfs', title: '专票/对外/发票份数', width: 150, align: "center", sort: true},
                    {field: 'zpdwje', title: '专票/对外/金额', width: 150, align: "center", sort: true},
                    {field: 'zpdwse', title: '专票/对外/税额', width: 150, align: "center", sort: true},
                    {field: 'zpjsfpfs', title: '专票/接受/发票份数', width: 150, align: "center", sort: true},
                    {field: 'zpjsje', title: '专票/接受/金额', width: 150, align: "center", sort: true},
                    {field: 'zpjsse', title: '专票/接受/税额', width: 150, align: "center", sort: true},
                    {field: 'ppdwfpfs', title: '普票/对外/发票份数', width: 150, align: "center", sort: true},
                    {field: 'ppdwje', title: '普票/对外/金额', width: 150, align: "center", sort: true},
                    {field: 'ppdwse', title: '普票/对外/税额', width: 150, align: "center", sort: true},
                    {field: 'ppjsfpfs', title: '普票/接受/发票份数', width: 150, align: "center", sort: true},
                    {field: 'ppjsje', title: '普票/接受/金额', width: 150, align: "center", sort: true},
                    {field: 'ppjsse', title: '普票/接受/税额', width: 150, align: "center", sort: true},
                    {field: 'cbhj', title: '查补合计', width: 150, align: "center", sort: true},
                    {field: 'rkhj', title: '入库合计', width: 150, align: "center", sort: true},
                ]
            ]
            , toolbar: '#toolbar1'
        });
        //案源下发时间
        laydate.render({
            elem: '#ayxfsj'
            , type: 'date'
            , range: '~'
            , done: function (value, date, endDate) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value.split("~")[0];
                    endTime = value.split("~")[1];
                } else {
                    startTime = null;
                    endTime = null;
                }
            }
        });
        //立案时间起
        laydate.render({
            elem: '#yqjasj'
            , type: 'date'
            , value: null
            , done: function (value) {
                if (value !== null && value !== undefined && value !== "") {
                    yqjasjTime = value;
                } else {
                    yqjasjTime = null;
                }
            }
        });
        //查询
        form.on('submit(search)', function () {
            searchAjwhList();
        })
        //导出
        form.on('submit(export)', function () {
            exportAjwhList();
        })
        //页面查询条件重置按钮
        form.on('submit(reset)', function () {
            document.getElementById('searchForm').reset(); // 原生重置表单
            $('#ayxfsj').val(''); // 清空输入框
            startTime = null; // 重置开始时间
            endTime = null; // 重置结束时间
            form.render(); // 重新渲染 Layui 的动态组件
        })

        //查询案件信息
        function searchAjwhList() {
            tableIns1.reload({
                contentType: 'application/json'
                , headers: {
                    "authorization": token,
                }
                , where: {
                    "nsrsbh": $("#nsrsbh").val(),
                    "nsrmc": $("#nsrmc").val(),
                    "jcajbh": $("#jcajbh").val(),
                    "startTime": startTime,
                    "endTime": endTime,
                    "cxbz": "qs"
                }, page: {
                    curr: 1 //重新从第 1 页开始
                }
            }, false);
        }

        //导出案件信息
        function exportAjwhList() {
            layer.confirm('确定导出所有数据?', {icon: 3, title: '提示'}, function (index) {
                const mapArr = {
                    "nsrsbh": $("#nsrsbh").val(),
                    "nsrmc": $("#nsrmc").val(),
                    "jcajbh": $("#jcajbh").val(),
                    "startTime": startTime,
                    "endTime": endTime,
                    "cxbz": "qs"
                };
                CoreUtil.sendPost("/attention/attentionMgr/exportAjwhTable", mapArr, function (res) {
                    if (res.code === 0) {
                        const data = res.data;
                        if (!CoreUtil.isEmpty(data)) {
                            //全部导出
                            table.exportFile(tableIns1.config.id, data, 'xls');
                            //导出时阻止页面刷新
                            $(".layui-form").submit(function (e) {
                                e.preventDefault();
                            })
                        } else {
                            layer.alert('未查询到需要导出的数据！', {icon: 2});
                        }
                    }
                });
                layer.close(index);
            });
        }
    });
</script>
</body>

</html>